//
// DepDependency
//
// Copyright (C) jextra.net.
//
//  This file is part of the net.jextra.dep Library.
//
//  The net.jextra.dep Library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  The net.jextra.dep Library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with the net.jextra.dep Library; if not, write to the Free
//  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
//  02111-1307 USA.
//

package net.jextra.dep;

/**
 * <p>
 * Represents a single entry in a depDef file. {@link DepDependency}s usually get resolved into concrete 
 * {@link DepComponent}s.
 * </p>
 */
public class DepDependency
{
    // ============================================================
    // Fields
    // ============================================================

    private String name;
    private String versionPattern;
    private String scope;
    private boolean optional;

    private boolean missing;

    // ============================================================
    // Methods
    // ============================================================

    // ----------
    // public
    // ----------

    public void setName( String name )
    {
        this.name = name;
    }

    /**
     * Unique name of the dependency. This includes the path in the repo but does not include the version 
     * (e.g. net.jextra.crack).
     */
    public String getName()
    {
        return name;
    }

    /**
     * Version number pattern specified in depDef file.
     */
    public String getVersionPattern()
    {
        return versionPattern;
    }

    public void setVersionPattern( String versionPattern )
    {
        this.versionPattern = versionPattern;
    }

    public String getScope()
    {
        return scope;
    }

    public void setScope( String scope )
    {
        this.scope = scope;
    }

    public boolean isOptional()
    {
        return optional;
    }

    public void setOptional( boolean optional )
    {
        this.optional = optional;
    }

    public boolean isMissing()
    {
        return missing;
    }

    public void setMissing( boolean missing )
    {
        this.missing = missing;
    }

    @Override
    public String toString()
    {
        if ( getVersionPattern() != null )
        {
            return String.format( "{name=%s,versionPattern=%s}", getName(), getVersionPattern() );
        }

        return String.format( "{name=%s}", getName() );
    }

    @Override
    public boolean equals( Object obj )
    {
        if ( obj == null || !( obj instanceof DepDependency ) )
        {
            return false;
        }

        DepDependency other = (DepDependency) obj;

        return other.toString().equalsIgnoreCase( toString() );
    }

    @Override
    public int hashCode()
    {
        return name == null
            ? 0 : name.hashCode();
    }
}
